package com.itheima.controller;

import com.itheima.mapper.SubjectMapper;
import com.itheima.pojo.HmSubjects;
import com.itheima.pojo.HmSubjectsDirectorys;
import com.itheima.service.DirectorysService;
import com.itheima.util.HmSubjectsDirectorysDto;
import com.itheima.util.PageResult;
import com.itheima.util.Success;
import com.itheima.util.SubjectsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//学科管理下的目录
@RestController
@RequestMapping("/directorys")
public class DirectorysController {
    @Autowired
    private DirectorysService directorysService;
    //目录的分页查询
    @GetMapping
    public PageResult findByPage(Integer page,Integer pagesize,String directoryName,Integer state){
        PageResult pageResult = directorysService.findByPage(page,pagesize,directoryName,state);
        return pageResult;
    }
    //目录修改
    @PutMapping("/{id}")
    public void Update(@PathVariable Integer id, @RequestBody HmSubjectsDirectorys hsd){
        directorysService.updateAll(id,hsd);
    }
    //项目禁用和启用
    @PostMapping("/{id}/{state}")
    public Success updateState(@PathVariable Integer id, @PathVariable Integer state){
        directorysService.update(id, state);
        return new Success(true);
    }
    //新增目录
    @PostMapping
    public void add(@RequestBody HmSubjectsDirectorys hsd){
        directorysService.add(hsd);
    }
    //删除目录
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id){
        directorysService.delete(id);
    }

    /**
     * 根据学科id查找目录
     */
    @GetMapping("/simple")
    public List<SubjectsResult> findById(Integer subjectID){
        return directorysService.findById(subjectID);
    }
}
